package com.tqjc.system.common.controller;

import java.util.Date;

import com.tqjc.system.core.config.web.DateConvertEditor;
import com.tqjc.system.core.config.web.IntegerConvertEditor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;

/**
 * 基础controller
 *
 * @author teli_
 */
@Slf4j
public class BaseController {

    @Autowired
    HttpServletRequest request;

    public BaseController setAttr(String key, Object value) {
        request.setAttribute(key, value);
        return this;
    }

    public Object getAttr(String key) {
        return request.getAttribute(key);
    }

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        // Date 类型转换
        binder.registerCustomEditor(Date.class, new DateConvertEditor());
        binder.registerCustomEditor(int.class, new IntegerConvertEditor());
    }


}
